using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace Pampa.WebControls
{
    public class BaseDesigner : System.Web.UI.Design.ControlDesigner
    {
        public override string GetDesignTimeHtml()
        {
            System.IO.StringWriter sw = new System.IO.StringWriter();
            System.Web.UI.HtmlTextWriter tw = new System.Web.UI.HtmlTextWriter(sw);

            try
            {
                RenderContainer(tw, ((WebControl)Component));
            }
            catch (Exception)
            {
                return String.Format("Error");
            }
            finally
            {
                tw.Flush();
            }

            string tmp = sw.ToString();

            tw.Close();
            tw = null;
            sw.Close();
            sw = null;

            return tmp;
        }

        public override bool AllowResize
        {
            get { return true; }
        }

        public override System.Collections.ICollection AssociatedComponents
        {
            get { return base.AssociatedComponents; }
        }

        protected virtual void RenderContainer(HtmlTextWriter writer, WebControl control)
        {
            writer.AddAttribute("id", control.ID);
            writer.AddStyleAttribute("height", control.Height.ToString());
            writer.AddStyleAttribute("width", control.Width.ToString());

            writer.RenderBeginTag(HtmlTextWriterTag.Div);

            writer.WriteLine(control.ID);

            writer.RenderEndTag();
        }
    }
}
